#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#include <immintrin.h>
//#include <emmintrin.h>
#define ll long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define fi first
#define se second
#define pii pair<int,int>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=2e6+5,base=999983,Mod=998244353;
const int base2=1000033,Mod2=1e9+7;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(int &x,int y){(x=x+y+Mod)%=Mod;}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}
int n;
char s[N]; 
int ch[N][2],cnt=1;
int lst[N],siz[N];
multiset<int>q[N],use[N];
int del[N],dell[N];
int ans=0;

void dfs(int x){
	del[x]=0; dell[x]=0;
	if(!ch[x][0]&&!ch[x][1]){
		q[x].insert(0);
		For(j,1,siz[x]){
			if(!q[x].size()){
				int p=*use[x].begin();
				use[x].erase(use[x].find(p));
				ans+=p+2;
				use[x].insert(p+1);
				use[x].insert(p+1);
			}
			else{
				int p=*q[x].begin();
				q[x].erase(q[x].find(p));
				ans+=p;
				use[x].insert(p);
			}
		}
		return ;
	}
	else
		For(j,0,1){
			if(ch[x][j]){
				dfs(ch[x][j]);
				del[ch[x][j]]++;
				if(q[ch[x][j]].size()>q[x].size()){
					q[x].swap(q[ch[x][j]]);
					swap(del[x],del[ch[x][j]]);
				}
				for(auto v:q[ch[x][j]]){
					q[x].insert(v+del[ch[x][j]]-del[x]);
				}q[ch[x][j]].clear();
				dell[ch[x][j]]++; 
				if(use[ch[x][j]].size()>use[x].size()){
					use[x].swap(use[ch[x][j]]);
					swap(dell[x],dell[ch[x][j]]);
				}
				for(auto v:use[ch[x][j]]){
					use[x].insert(v+dell[ch[x][j]]-dell[x]);
				}use[ch[x][j]].clear();
			}
			else q[x].insert(1-del[x]);
		}
	For(j,1,siz[x]){
		if(!q[x].size()){
			int p=*use[x].begin();
			use[x].erase(use[x].find(p));
			ans+=p+dell[x]+2;
			use[x].insert(p+1);
			use[x].insert(p+1);
		}
		else if(!use[x].size()){
			int p=*q[x].begin();
			q[x].erase(q[x].find(p));
			ans+=p+del[x];
			use[x].insert(p+del[x]-dell[x]);
		}else{
			if(*use[x].begin()+dell[x]+2<=*q[x].begin()+del[x]){
				int p=*use[x].begin();
				use[x].erase(use[x].find(p));
				ans+=p+dell[x]+2;
				use[x].insert(p+1);
				use[x].insert(p+1);
				
			}else{
				int p=*q[x].begin();
				q[x].erase(q[x].find(p));
				ans+=p+del[x];
				use[x].insert(p+del[x]-dell[x]);
				
			}
		} 
	}
}
signed main(){
	freopen("id.in","r",stdin);
	freopen("id.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	n=read();
	For(i,1,n){
		scanf("%s",s+1);
		int len=strlen(s+1);
		int p=1;
		For(j,1,len){
			int c=s[j]-'0';
			if(!ch[p][c])ch[p][c]=++cnt;
			p=ch[p][c];
		}siz[p]++;
	}
	dfs(1);
	printf("%d\n",ans);
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

